package bsi.vn.FirstApp;

import java.util.Locale;

import bsi.vn.Lib.ProcessFunc;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class ATMDetailFragmentActivity extends FragmentActivity {

	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;
	private int iATMId = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle extras = getIntent().getExtras();
		if (extras == null) {
			return;
		}
		iATMId = extras.getInt("ATMId");
		
		setContentView(R.layout.activity_atmdetail_fragment);
		mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		 MenuInflater menuInflater = getMenuInflater();
	        menuInflater.inflate(R.menu.atmsearch, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		if(item.getItemId() != R.id.menu_sub){
			startActivity(ProcessFunc.MenuAction(this, item));
		}
		return super.onMenuItemSelected(featureId, item);
	}

	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			Fragment fragment = new ATMGeneralFragment();
			switch (position) 
			{
				case 0:
					fragment = new ATMGeneralFragment(ATMDetailFragmentActivity.this, iATMId);
					break;
				case 1:
					fragment = new ATMTicketFragment(ATMDetailFragmentActivity.this, iATMId);
					break;
				case 2:
					fragment = new ATMContractFragment(ATMDetailFragmentActivity.this, iATMId);
					break;
			}
			return fragment;
		}

		@Override
		public int getCount() {
			// Show 3 total pages.
			return 3;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			Locale l = Locale.getDefault();
			switch (position) {
			case 0:
				return getString(R.string.ad_title_General).toUpperCase(l);
			case 1:
				return getString(R.string.ad_title_ATMTicket).toUpperCase(l);
			case 2:
				return getString(R.string.ad_title_ATMContract).toUpperCase(l);
			}
			return null;
		}
	}
}
